﻿//寻求帮助弹出框
//时间 几天前 几分钟前
var haveMyid=true;//是否有cookie.MYID 用于所有事件点击
var now = new Date().getTime();
function getDateTimeStamp(dateStr){
    dateStr=dateStr.replace(/T/g,' ');
    dateStr=dateStr.replace(/\.[0-9]+/g,'');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 60000;
    var hour = 3600000;
    var day = 86400000;
    var month = 2592000000;
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}
//------------------------------------
var toparrow=document.getElementsByClassName("top-arrow")[0]; //上箭头
var findhelp=document.getElementById("findhelp"); //外部帮助按钮
var RequestAnswersDrawer=document.getElementById("outsidehelp"); //外部帮助弹出框
findhelp.onclick=function(){
    if(haveMyid){
        if(toparrow.style.display=="none"){
            toparrow.style.display="block";
            var timer1=setInterval(function(){
                if(parseFloat($("#outsidehelp").css("height"))>141){
                    clearInterval(timer1);
                }else{
                    var height=parseFloat( $("#outsidehelp").css("height"));//outsidehelp
                    $("#outsidehelp").css("height",height+47);
                }
            },40)
        }else{
            var timer2=setInterval(function(){
                if(parseFloat($("#outsidehelp").css("height"))<=0){
                    clearInterval(timer2);
                    toparrow.style.display="none";
                }else{
                    var height=parseFloat( $("#outsidehelp").css("height"));//outsidehelp
                    $("#outsidehelp").css("height",height-47);
                }
            },40)
        }
    }
};
//模态框淡入淡出
var overflowlist=document.getElementsByClassName("overflow"); //三个小点
var modalbg=document.getElementsByClassName("modal_bg1")[0]; //弹出框背景
var modal=document.getElementById("action_menu_container1"); //弹出框
var cancel=document.getElementsByClassName("cancel1")[0];   //弹出框中取消按钮
var timer;
for(var i=0;i<overflowlist.length;i++){
    overflowlist[i].onclick=function(){
        if(haveMyid){
            modalbg.style.display="block";
            modal.style.display="block";
        }
    }
}
cancel.onclick=function(){
    if(modalbg.style.display=="block"&&modal.style.display=="block"){
        modalbg.className+=' animate_out';
        modal.className+=' animate_out';
    }
    timer=setTimeout(changeclass,100);
};
function changeclass(){
    modalbg.className='modal_bg';
    modal.className='action_menu_container';
    clearTimeout();
    timer=null;
    changedisplay();
}
function changedisplay(){
    modalbg.style.display="none";
    modal.style.display="none";
}
var sta=1;//问题状态 是否结帖 1未结帖 0结帖
var quserid="";
var currentIndex=1;
var pageSize = 10;
var qid,id;
var canEdit=false;//问题能否编辑
var upnick=[];//所有点赞者昵称
var upuserid=[];//所有点赞者ID
if(location.href.match("qid")){
    var reg=/(qid=)([0-9]*)/;
    var urlfrom=location.href;
    qid=urlfrom.match(reg).splice("=")[2];
    id=$.cookie("MYID");
}else{
    qid=$.cookie("myqid");
    id=$.cookie("MYID");
}
//var imgboxheight=parseInt(document.body.clientWidth*0.3)+"px";
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
function contentshowloadimg(e){
    $(e).css("opacity","1");
}
//点击图片展示放大图片
var winscrolltop=0;
function showbigimg(e){
    winscrolltop=$(window).scrollTop();
    $("#page_wrapper").css("display","none");
    $("#showimg").attr("src", e.src);
    $("#digimgplace").css("display","block");
    var bigheight=$("#digimgplace").height();
    var imgheight=$("#showimg").height();
    if(bigheight>imgheight){
        //$("#showimg").css("marginTop",(bigheight-imgheight)/2);
    }
};
$("#digimgplace").click(function(){
    if(haveMyid){
        if($("#allanswer").css("display")==="block"){
            $("#digimgplace").css("display","none");
        }else{
            $("#page_wrapper").css("display","block");
            $("#digimgplace").css("display","none");
        }
        if(winscrolltop>0){
            $(window).scrollTop(winscrolltop);
        }
    }
});
//昵称
if((!$.cookie("MYNICK")||/undefined/.test($.cookie("MYNICK")))||!$.cookie("MYAVA")){
    $.ajax({
        type: "post",
        url: userurl,
        data: {"userId": id},
        datatype: "json",
        success: function (data) {
            $.cookie("MYNICK", data.Data.userNick);
            $.cookie("MYID", data.Data.userId);
            $.cookie("MYAVA", data.Data.userAva);
        }
    });
}
//微信转发
var sharetitle="";
var sharemoney= 0;//微信转发使用数据 转发金额 悬赏金额；
var sharenick="";//微信转发标题
if($.cookie('MYNICK')){sharenick= $.cookie('MYNICK')+'分享：'}
function wxshare(){
    //修改转发地址
    //来自分享
    //连接微信  转发
    (function(){
        var qid=(location.href).match(/qid=[0-9]+/)[0].match(/[0-9]+/)[0];
        var fromuser;
        if(/fromuser/.test(location.href)){
            fromuser=(location.href).match(/fromuser=[0-9a-z]+/)[0].split("=")[1];
        }else if($.cookie("fromuser")&&/[0-9]/.test($.cookie("fromuser"))){
            fromuser=$.cookie("fromuser");
        }else if($.cookie("MYID")){
            fromuser=$.cookie("MYID");
        }
        $.ajax({
            type:"GET",
            url:"GetSign.ashx?p=weixin/questiondetail.html?qid="+qid+"#fromuser="+fromuser,
            success:function(data){
                timestampone=data.timestamp;
                nonceStrone=data.nonceStr;
                signatureone=data.signature;
                wx.config({
                    debug:false,
                    appId: 'wx658c34793ecfd9f9',
                    timestamp:timestampone, //时间戳
                    nonceStr:nonceStrone,  //随机字符串
                    signature:signatureone,  //SHA1编码
                    jsApiList: [
                        // 所有要调用的 API 都要加到这个列表中
                        "onMenuShareTimeline","onMenuShareAppMessage"
                    ]
                });
            }
        })
    })();
    wx.ready(function(){
        var qid=(location.href).match(/qid=[0-9]+/)[0].match(/[0-9]+/)[0];
        var fromuser;
        if(/fromuser/.test(location.href)){
            fromuser=(location.href).match(/fromuser=[0-9a-z]+/)[0].split("=")[1];
        }else if($.cookie("fromuser")&&/[0-9]/.test($.cookie("fromuser"))){
            fromuser=$.cookie("fromuser");
        }else if($.cookie("MYID")){
            fromuser=$.cookie("MYID");
        }
        //var newsurl=newsurl.replace(/http:\/\//,"");
        //微信转发到朋友圈
        wx.onMenuShareTimeline({
            title:sharenick+sharemoney+'元 '+sharetitle.replace(/[\r\n]/g,"")+'" 关键词：'+sharekeyword, // 分享标题
            link:"http://www.pulu.com/weixin/questiondetail.html?qid="+qid+"#fromuser="+fromuser, // 分享链接
            imgUrl:"https://www.pulu.com/weixin/img/puluweixin.jpg", // 分享图标
            success: function () {
                // 用户确认分享后执行的回调函数
                //增加转发次数
                $.ajax({
                    type:"post",
                    url:addSendWXNumurl,
                    data:{"qid":qid,"qtype":2},
                    success:function(){
                        alert("分享成功");
                    }
                })
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                //alert("取消分享");
            }
        });
//微信转发给好友
        wx.onMenuShareAppMessage({
            //title:'(悬赏'+sharemoney+'元)'+sharetitle.replace(/[\r\n]/g,""), // 分享标题
            title:sharenick+sharemoney+'元 '+sharetitle.replace(/[\r\n]/g,"")+'" 关键词：'+sharekeyword, // 分享标题
            desc: 'Pulu铺路经验，好朋友互相铺路', // 分享描述
            link:"http://www.pulu.com/weixin/questiondetail.html?qid="+qid+"#fromuser="+fromuser, // 分享链接
            imgUrl:"https://www.pulu.com/weixin/img/puluweixin.jpg", // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                // 用户确认分享后执行的回调函数
                //增加转发次数
                $.ajax({
                    type:"post",
                    url:addSendWXNumurl,
                    data:{"qid":qid,"qtype":2},
                    success:function(){
                        alert("分享成功");
                    }
                })
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                //alert("取消了");
            }
        });
    });
}
//相关问题判断能否进入
function moneytest(e){
    //判断能不能去看详情页
    var thiseid= e.dataset.qid;
    if($.cookie("MYID")){
        location.href='questiondetail.html?qid='+thiseid+"#fromuser="+id;
    }else{
        location.href='questiondetail.html?qid='+thiseid+"#fromuser="+$.cookie("MYID");
    }
}
var firstimg="";//用于QQ 微信分享展示 第一张图片
var eid;
$("#gotoexpbtn").click(function(){
    if($.cookie("MYID")){
        location.href="shareexppage.html?eid="+eid+"#fromuser="+id;
    }
});
//跳转他人详情页
function usergohref(i){
    if($.cookie("MYID")){
        var userReg=new RegExp($.cookie("MYID"));
        if(userReg.test(i.dataset.href)){
            location.href="setpage.html";
        }else{
            location.href= i.dataset.href;
        }
    }
}
//发高额 我也来说说
function gotoheiexp(data){
    if($.cookie("MYID")){
        if($.cookie("validateLevel")!=1&&$.cookie("validateLevel")!=2){
            $("#canNotSend").css("display","block");
            $("html").css("overflow-y","hidden");
        }else{
            var eid=data.dataset.keyword;
            if(is_weixn()){
                $.cookie("expkeyword",eid);
                $.cookie("expType","");
                $.cookie("sendque","question");
                location.href="http://www.pulu.com/weixin/sendexpgpc.html";
            }
            else{
                location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+"&keyword="+eid+"&sendque=question";
            }
        }
    }
}
$("#canNotSend .closeBtn").click(function(){
    $("#canNotSend").css("display","none");
    $("html").css("overflow-y","auto");
});
function goAuthenticate(){
    location.href="authenticate.html?goPage=goQue"
}
//展示点赞者
function showuper(nick,id){
    var upnum= nick.length;
    var inum=upnum;
    var lastword="";
    var shownick=[];
    if(upnum>3){inum=3;lastword="等"};
    for(var i=0;i<upnum;i++){
        if(id[i]== $.cookie("MYID")){
            $("#goodbtn").css("backgroundImage","url(img/redheart.png)");
            $("#goodbtn .word").attr("class","word clicked");
        }
        if(i<inum){shownick.push(nick[i]);}
    }
    var allupnick=shownick.join(",")+lastword;
    $("#upnum2").html(allupnick);
    $("#upnum").html(upnum);
    $(".allupers").css("display","block");
}
$().ready(function(){
    var questionUserId="";
    //获得经验内容
    var sendid=id;
    if($.cookie("MYID")&&/[0-9]/.test($.cookie("MYID"))){sendid=$.cookie("MYID");}
    //获得问题
    $.ajax({
        type:"get",
        url:getquedetialurl+qid+"&userId="+sendid,
        datatype: "json",
        success:function(data){
            sharemoney='"悬赏'+(data.Data.score)/100;//微信转发
            if(data.Data.state==1&&data.Data.userId==id){
                $("#changeexp").css("display","block");//编辑修改
            }
            (data.Data.canEdit)?canEdit=true:canEdit=false;
            //关键词
            if(data.Data.keyWords){
                sharekeyword=data.Data.keyWords;
                $(".TopicListItems2").append("<span>关于：</span>");
                $(".QuestionTopics.has_topics").attr("data-keyword",data.Data.id);
                var keywordarr=data.Data.keyWords.split(",");
                for(var k=0;k<keywordarr.length;k++){$(".TopicListItems2").append("<span>"+keywordarr[k]+"</span>");}
                $(".TopicListItems2").append("<span>我也来说说</span>");
            }
            //点赞数
            var upnum=0;
            if(data.Data.QUpUsers){upnum=data.Data.QUpUsers.length}
            if(upnum>0){
                for(var i=0;i<upnum;i++){
                    upnick.push(data.Data.QUpUsers[i].nick);
                    upuserid.push(data.Data.QUpUsers[i].userId);
                }
                showuper(upnick,upuserid);
            }else{
                $(".allupers").css("display","none");
                $("#upnum").html(0);
            }
            //定位
            if(data.Data.location&&data.Data.location.length>0){
                $(".locationplace").css("display","block");
                $(".locationplace span").html(data.Data.location);
            };
            //提示
            //$("#showrule").html(data.Data.noticeMsg);
            $("#showrule").html("转发此悬赏，好友答对就得"+(data.Data.score)/500+"元");
            //console.log(keywordarr);
            if(data.Data.userId!=id){questionUserId=data.Data.userId;}
            if(data.Data.state===0){
                sta=0;
                //滚动right修改 盖住评论
                $("#qrcode").css("right","41px");
                document.getElementById("huidabtn").style.display="none";
                document.getElementById("findhelp").style.display="none";
                document.getElementById("friendhelp").style.display="none";
                $("#closeimg").css("display","block");
            }
            questionscore=data.Data.score;//有没有钱
            quserid=data.Data.userId;
            //问题转经验提醒
            if($.cookie("goChangeQue")&&$.cookie("goChangeQue")==qid&&data.Data.userId==id){
                $.cookie("goChangeQue","");
                $("#delmynews").css("display","block");
            }
            var changetitle=data.Data.content.replace(/[\r\n\s]/g,"");
            if(data.Data.content.length>50){changetitle=(data.Data.content).substr(0,50).replace(/[\r\n\s]/g,"");}

            $("title").html(sharenick+sharemoney+'元 '+changetitle+'" 关键词：'+sharekeyword);
            sharetitle=changetitle;
            $(".gettitle").html(data.Data.title);
            var facecode=codetoface(data.Data.content);
            //问题转经验 跳至经验页
            if(data.Data.ExpId!=0){
                $(".getcontent").css("display","none");
                $("#gotoexp").css("display","block");
                $("#closeimg").css("display","none");
                $("#showrule").css("display","none");
                $(".ActionBar.Question .action_bar_inner").css("display","none");//三个点 点赞
                eid=data.Data.ExpId;
            }
            $(".getcontent").html(facecode);
            $("#sharetitleword div").html(data.Data.title);
            $(".senderinfo .lf span").html(parseFloat(data.Data.score)/100);//经验有多少钱
            //if(data.Data.isHideName==1){ //(问题匿名)----------------------------------------------
            //    $(".senderinfo .rt #sendernick").append("<a>匿名</a>");
            //}else{
            //    var thisRealName="";
            //    if(data.Data.realName){thisRealName=" ("+data.Data.realName+")";}
            //    $(".senderinfo .rt #sendernick").append("<a style='color:#41A5ED;' onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+data.Data.userId+"'>"+data.Data.userNick+thisRealName+"</a>");
            //}
            var fromLevelWord="";
            if(data.Data.Mlevel==3||data.Data.Tlevel==3){
                fromLevelWord="来自高层"
            }else if(data.Data.Mlevel==2||data.Data.Tlevel==2){
                fromLevelWord="来自同层"
            }else if(data.Data.Mlevel===1||data.Data.Tlevel===1){
                fromLevelWord="来自普通层"
            }
            if(data.Data.userId== $.cookie("MYID")){fromLevelWord="来自自己"}
            $(".senderinfo .rt #sendernick").append("<a style='color:#41A5ED;' onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+data.Data.userId+"'>"+fromLevelWord+"</a>");
            var titletim=getDateDiff(getDateTimeStamp(data.Data.cTime));
            if(titletim&&titletim.length>0){$(".senderinfo .rt #sendertime").html(titletim);}
            else{$(".senderinfo .rt #sendertime").html("刚刚");}
            if(data.Data.imgList&&data.Data.imgList.length>0){
                firstimg="http://42.62.66.198:8003/"+data.Data.imgList[0].imgPath;//用于QQ 微信分享展示 第一张图片
                for(var r=0;r<data.Data.imgList.length;r++){
                    $("#qimgsplace").append("<div class='imgbox contentImg'><img src='http://42.62.66.198:8003/"+data.Data.imgList[r].imgPath+"' onload='contentshowloadimg(this)' style='opacity:0;'/></div>");
                }
            }
            if(data.Data.score>0&&questionUserId!=id){
                $(".senderinfo .lf").css("display","block");
            }
            //最佳回答--------------------------------------------------------------
            //var db;
            //if(data.Data){db=data.Data.proBestAnswerList;}
            //if(db&&db.length>0){
            //    for(var l2=0;l2<db.length;l2++){
            //        var answerimgs=""; //保存图片代码段
            //        var htmlword="";//保存图片代码段
            //        var isclick="";
            //        var tim="";//保存时间
            //        //判断是否有图片
            //        if(db[l2].imgList.length>0){
            //            console.log("有图片");
            //            for(var li=0;li<db[l2].imgList.length;li++){htmlword+="<div class='imgbox'><img src='http://42.62.66.198:8003/"+db[l2].imgList[li].imgPath+"' onclick='showbigimg(this)' onload='showloadimg(this)' style='display:none;'/></div>";}
            //            if(htmlword){answerimgs="<div class='qtext_para qimgs answerimgs' style='display:block;'>"+htmlword+"</div>";}
            //        };
            //        //是否已经有点赞
            //        var goodnum=0;
            //        var upers="";
            //        var displayword="none;border-top: 1px solid #EDEDED;";//点赞区展示 及 上边线
            //        var chatcssword="style='border-top: 1px solid #EDEDED;'";//聊天区域边线
            //        if(db[l2].upUsers.length>0){
            //            goodnum=db[l2].upUsers;
            //            displayword="-webkit-box;border-top: 1px solid #EDEDED;";
            //            chatcssword="";
            //            for(var lu=0;lu<db[l2].upUsers.length;lu++){
            //                db[l2].upUsers[lu].index=lu;
            //                if(db[l2].upUsers[lu].upUserId===id){isclick=" isclicked";}
            //                upers+="<span class='heartspan' data-uid='"+db[l2].upUsers[lu].upUserId+"'>"+db[l2].upUsers[lu].upUserNick+"</span>";
            //            }
            //        }
            //        //获得时间
            //        var regtime=/([0-9\-])*/;
            //        tim=getDateDiff(getDateTimeStamp(db[l2].cTime));
            //        var sign="";
            //        //头像 昵称
            //        var unick=db[l2].userNick;
            //        var headerimg="<a href='otherpeoplepage.html?otherid="+db[l2].userId+"'><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            //        if(db[l2].userAva){
            //            if(db[l2].ishideName===1){
            //                headerimg="<a><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            //                unick="匿名";
            //            }else{
            //                headerimg="<a href='otherpeoplepage.html?otherid="+db[l2].userId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+db[l2].userAva+"' onload='showloadimg(this)' style='display:none;'></a>";
            //            }
            //        }else{
            //            if(db[l2].ishideName===1){
            //                headerimg="<a><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            //                unick="匿名";
            //            }else{
            //                headerimg="<a href='otherpeoplepage.html?otherid="+db[l2].userId+"'><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            //            }
            //        }
            //        var newcontent=codetoface(db[l2].content);
            //        if(tim){}else{tim="刚刚";}
            //        var pinglun="<a class='commentbtn' id='c"+db[l2].answerId+"' data-uid='"+db[l2].userId+"'></a>";;
            //        //二级评论
            //        var secondword="";
            //        if(db[l2].commentList&&db[l2].commentList.length>0){
            //            for(var r1=0;r1<db[l2].commentList.length;r1++){
            //                var replyto="";
            //                if(db[l2].commentList[r1].replyToUserNick){replyto=" 回复 "+db[l2].commentList[r1].replyToUserNick;}
            //                var secondfaceword=codetoface(db[l2].commentList[r1].content);
            //                secondword+="<div class='secondword' id='second"+db[l2].commentList[r1].commentId+"'><span class='username'>"+db[l2].commentList[r1].userNick+replyto+"：</span><span class='userword commentbtn' data-replyname='"+db[l2].commentList[r1].userNick+"' data-reply='"+db[l2].commentList[r1].commentId+"' id='c"+db[l2].answerId+"'>"+secondfaceword+"</span></div>";
            //            }
            //            //添加点赞
            //            secondword="<div class='secondchat' "+chatcssword+"><div class='secondlogo'></div><div class='secondwordplace'>"+secondword+"<div></div>";
            //        }
            //        $("#bestanswer").append("<div class='othersanswer'> <div class='AnswerPagedList PagedList'> <div class='Answer on_question_page'> <div class='user-pic'>"+headerimg+"</div> <div class='comment'> <div class='username'> <span> "+unick+" </span> <span class='rt'>"+tim+"</span> </div> <div class='comment-entry'> "+newcontent+answerimgs+"</div><div class='comment-btnplace'>"+pinglun+"<a class='Upvote "+isclick+" upv"+db[l2].answerId+"' onclick='addgoodftn(this)' ></a></div><div class='heartli answer"+db[l2].answerId+"' style='display:"+displayword+"'><span class='heartplacelogo'></span><div class='secondwordplace'>"+upers+"</div></div>"+secondword+"</div> </div> </div> </div> </div> </div>");
            //    }
            //    htmlword="";
            //    answerimgs="";
            //    isclick="";
            //    $("#bestanswer").css("display","block");
            //    //最佳回答评论
            //    comment();
            //}
            //回答者
            getanswer(qid,currentIndex,3,"main");
            //微信转发
            wxshare();
        }
    });
    //获得相关问题
    function relevantnews(currentIndex){
        $.ajax({
            type:"get",
            datatype:"json",
            url:relevanturl+id+"&currentIndex="+currentIndex+"&pageSize=5&questionId="+qid+"&qtype=2",
            success:function(d){
                //console.log("相关经验");
                //console.log(d);
                if(d.Data&&d.Data.length>0){
                    for(var i=0;i<d.Data.length;i++){
                        var moneyspan="";
                        if(d.Data[i].score>0){
                            moneyspan="<span class='rt' style='padding-left:16px;padding-right:20px;'>"+(parseFloat(d.Data[i].score)/100)+"</span>";
                        }
                        $("#Relevantq").append("<li class='Cell'><a class='tc_inner' onclick='moneytest(this)' data-qid="+d.Data[i].id+"><span class='tc_text'>"+d.Data[i].title+"</span>"+moneyspan+"</a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                    }
                    if(d.Data.length<5){
                        $("#morequ").css("display","none");
                    }else{
                        $("#morequ").css("display","block");
                    }
                }else{
                    $("#Relevantq").append("<li class='Cell' style='background:#FFF'><a class='tc_inner' style='text-align: center'><span class='tc_text' style='font-size:15px;color:#999'>无相关推荐</span></a></li>");
                    $("#morequ").css("display","none");
                    //if(currentIndex==1){
                    //    console.log(currentIndex);
                    //    $(".RelatedQuestions").css("display","none");
                    //}
                }

            }
        });
    }
    relevantnews(1);//前五条相关经验
    //更多相关经验
    $("#morequ").click(function(){
        if(haveMyid){
            $.ajax({
                type:"get",
                datatype:"json",
                url:relevanturl+id+"&currentIndex=2&pageSize=5&questionId="+qid+"&qtype=2",
                success:function(d){
                    if(d.Data&&d.Data.length>0){
                        for(var i=0;i<d.Data.length;i++){
                            var moneyspan="";
                            if(d.Data[i].score>0){
                                moneyspan="<span class='rt' style='padding-left:16px;padding-right:20px;'>"+(parseFloat(d.Data[i].score)/100)+"</span>";
                            }
                            $("#Relevantq").append("<li class='Cell'><a class='tc_inner' onclick='moneytest(this)' data-qid="+d.Data[i].id+"><span class='tc_text'>"+d.Data[i].title+"</span>"+moneyspan+"</a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                        }
                    }else{
                        $("#morequ").css("display","none");
                    }

                }
            });
            $("#morequ").css("display","none");
        }
    });
    //弹出回答页面
    $(".answerbtn").click(function(){
        if(haveMyid){
            var shareUserId="";

            if($.cookie("fromuser")&&!/fromuser/.test($.cookie("fromuser"))){
                //alert("回答frome："+$.cookie("fromuser"));
                //$.cookie("fromuser") 一直存在可能为自己 判断重复性 以$.cookie("shareUserId")的优先级为主
                if($.cookie("fromuser")!==id){
                    shareUserId="&shareUserId="+$.cookie("fromuser");
                }
            }
            if($.cookie("shareUserId")){
                //alert("回答share："+$.cookie("shareUserId"));
                shareUserId="&shareUserId="+$.cookie("shareUserId");
            }
            //alert($.cookie("shareUserId")+":"+$.cookie("MYID"));
            $.cookie("fromquestiondetial",qid);
            if(!$.cookie("shareUserId")&&!$.cookie("fromuser")){
                fromuser=(location.href).match(/fromuser=[0-9a-z]+/)[0].split("=")[1];
                if($.cookie("MYID").length>10&&fromuser!=$.cookie("MYID")){
                    shareUserId="&shareUserId="+fromuser;
                }
            }
            //if(is_weixn()){
            //    $.cookie("shareUserId",shareUserId);
            //    location.href="https://www.pulu.com/weixin/answerpage.html?qid="+qid;
            //}else{
            //    //alert("../answerpage.html?id="+id+"&qid="+qid+shareUserId);
            //    location.href="https://www.pulu.com/answerpage.html?id="+id+"&qid="+qid+shareUserId;
            //}
            location.href="answerpage.html?id="+id+"&qid="+qid+shareUserId;
        }
    });
    //收藏
    $("#collectit").click(function(){
        if(haveMyid){
            $.ajax({
                type:"post",
                datatype:"json",
                url:"https://www.pulu.com/webapi/api/PuluCollection/Addpulu_collection",
                data:{"contentid":qid,"userid":id,"contenttype":2},
                success:function(data){
                    console.log(data);
                    $("#collectword a").html("收藏成功");
                    $("#collectword").css("display","block");
                    setTimeout(function(){
                        $("#collectword").css("display","none");
                    },1000);
                    clearTimeout();
                    if(modalbg.style.display=="block"&&modal.style.display=="block"){
                        modalbg.className+=' animate_out';
                        modal.className+=' animate_out';
                    }
                    function disnone(){
                        document.getElementById("collectword").style.display="none";
                    }
                    timer=setTimeout(changeclass,100);
                    setTimeout(disnone,1000);
                    clearTimeout();
                }
            })
        }

    });
    //转发 内部帮助
    var shareword=document.getElementById("shareword");
    var cancelbtn=document.getElementById("cancelbtn");
    var commentinput=document.getElementById("commentinput");
    var sendcommentbtn=document.getElementById("sendcommentbtn");
    //内部帮助 提醒谁看
    var callpersons=[];
    //悬赏转经验
    $("#delmynewscancel").click(function(){
        $("#delmynews").css("display","none");
    });
    $("#delmynewsok").click(function(){
        $("#delmynews").css("display","none");
        location.href="sendexpgpc.html#queChange="+qid+"#clear";
    });
});

//获得回答-------------------------------------------------------
var answerlength=1;// 1有回答  0没有回答了
var haveajax=0;
var isover=0;//控制页面滚动 0不能滚动
var cangetanswerurl="yes";//滚动加载
function getanswer(qid,currentIndex,pageSize,page){
    $.ajax({
        type:"get",
        url:getanswerurl+qid+"&pageSize="+pageSize+"&currentIndex="+currentIndex+"&userId="+id,
        datatype:"json",
        success:function(data){
            haveajax++;
            //所有回答---------------------------------------------------------------
            var dd;
            if(data.Data){
                dd=data.Data.proAnswerList;
                $(".evaluatenum").html("("+data.Data.answerCount+")");
            }
            if(dd&&dd.length>0&&dd.length===pageSize){
                answerlength=1;
                //console.log(answerlength);
                $("#addmoreanswerbtn").css("display","block");
            }else{
                //$("#addmoreanswerbtn").css("display","none");
                answerlength=0;
            }
            if((dd&&dd.length==0)||!dd){
                if(haveajax===2){
                    //第二次加载
                }else{
                    if(page==="main"){
                        $("#QuestionMain").css("display","none");
                        $("#addmoreanswerbtn").css("display","none");
                    }
                    cangetanswerurl="no";
                }
            }
            if(dd&&dd.length>0){
                $("#QuestionMain").css("display","block");
                for(var l=0;l<dd.length;l++){
                    var answerimgs=""; //保存图片代码段
                    var htmlword="";//保存图片代码段
                    var isclick="";
                    var tim="";//保存时间
                    //判断是否有图片
                    if(dd[l].imgList.length>0){
                        for(var li=0;li<dd[l].imgList.length;li++){
                            htmlword+="<div class='img'><img src='http://42.62.66.198:8003/"+dd[l].imgList[li].imgPath+"' onclick='showbigimg(this)' onload='showloadimg(this)' style='display:none;'/></div>";
                        }
                        if(htmlword){
                            answerimgs="<div class='comment-pic js_comment_pic' style='display:block;'><div>"+htmlword+"</div></div>";
                        }
                    };
                    //获得时间
                    var regtime=/([0-9\-])*/;
                    if(dd[l].cTime){
                        tim=getDateDiff(getDateTimeStamp(dd[l].cTime));
                    };
                    var sign="";
                    //是否是发布者 是否结帖了======
                    var gooverit="";
                    if(quserid===id&&sta===1&&dd[l].userId!=id){
                        gooverit="<span class='gooveritbtn'>选为答案</span>"
                    }
                    //最佳回答
                    var bestanswer="";
                    if(dd[l].IsSelect&&dd[l].IsSelect==1){
                        bestanswer="<div class='bestanswerimg'></div>";
                    }
                    //已赚取 已支出
                    var secondtitleword="";
                    secondtitleword="已赚取"+parseInt(dd[l].daysin)/100+"元 | 已支出"+parseInt(dd[l].daysout)/100+"元";
                    var pinglun="";
                    pinglun="<a class='commentbtn' id='c"+dd[l].answerId+"' data-uid='"+dd[l].userId+"'></a>";
                    //是否已经有点赞
                    //var upstylecode="";
                    var goodnum=0;//
                    var upers="";
                    var upnum=0;
                    var displayword="none;border-top: 1px solid #EDEDED;";//点赞区展示 及 上边线
                    var chatcssword="style='border-top: 1px solid #EDEDED;'";//聊天区域边线
                    if(dd[l].upUsers.length>0){
                        upnum=dd[l].upUsers.length;
                        goodnum=dd[l].upUsers;
                        displayword="-webkit-box;border-top: 1px solid #EDEDED;";
                        chatcssword="";
                        for(var lu=0;lu<dd[l].upUsers.length;lu++){
                            dd[l].upUsers[lu].index=lu;
                            if(dd[l].upUsers[lu].upUserId===id){isclick=" isclicked";console.log("自己点赞")}
                            upers+="<span class='heartspan' data-uid='"+dd[l].upUsers[lu].upUserId+"'>"+dd[l].upUsers[lu].upUserNick+"</span>";
                        }
                    }
                    //function reload(){
                    var tim=getDateDiff(getDateTimeStamp(dd[l].cTime));
                    //头像 昵称
                    var thisRealName="";
                    if(dd[l].realName){thisRealName=" ("+dd[l].realName+")"}
                    var unick=dd[l].userNick+thisRealName;
                    var headerimg="<a onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+dd[l].userId+"'><img class='portrait' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                    if(dd[l].userAva){
                        if(dd[l].ishideName===1){
                            headerimg="<a><img class='portrait' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                            unick="匿名";
                            secondtitleword="";
                        }else{
                            headerimg="<a onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+dd[l].userId+"'><img class='portrait' src='http://42.62.66.198:8003/"+dd[l].userAva+"' onload='showloadimg(this)' style='display:none;'></a>";
                        }
                    }else{
                        if(dd[l].ishideName===1){
                            headerimg="<a><img class='portrait' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
                            unick="匿名";
                            secondtitleword="";
                        }
                    }
                    var newcontent=codetoface(dd[l].content);
                    if(!tim){tim="刚刚";}
                    //二级评论
                    var secondword="";
                    if(dd[l].commentList&&dd[l].commentList.length>0){
                        for(var r1=0;r1<dd[l].commentList.length;r1++){
                            var replyto="";
                            if(dd[l].commentList[r1].replyToUserNick){
                                replyto=" 回复 <i>"+dd[l].commentList[r1].replyToUserNick+"</i>";
                            }
                            var secondfaceword=codetoface(dd[l].commentList[r1].content);
                            secondword+="<div id='second"+dd[l].commentList[r1].commentId+"' data-replyname='"+dd[l].commentList[r1].userNick+"' data-reply='"+dd[l].commentList[r1].commentId+"' data-eid='"+eid+"' data-uid='"+dd[l].commentList[r1].userId+"' data-id='c"+dd[l].answerId+"' onclick='comment(this)'><span class='username'><i>"+dd[l].commentList[r1].userNick+"</i>"+replyto+"：</span><span class='userword commentbtn'>"+secondfaceword+"</span></div>";
                        }
                        secondword="<div class='chatplace'><i></i><div class='secondword'>"+secondword+"</div></div>";
                    }
                    //没有二级评论 没有点赞
                    var commentstyle="";
                    if((!dd[l].upUsers||dd[l].upUsers.length==0)&&(!dd[l].commentList||dd[l].commentList.length==0)){commentstyle="style='display:none;'"}
                    //去星级 加图片区域
                    if(page==="main"){
                        $("#addmoreanswerbtn2").before("<div class='js_tag js_commentP'>"+bestanswer+"<div class='common-head-view'><div class='author-logo'>"+headerimg+"</div><div class='author-info'><div class='author-info1'><div class='author js_author' style='max-width: 330px;'>"+unick+"</div>"+gooverit+"</div><div class='author-info2'>"+secondtitleword+"</div></div></div><div class='comment-main js_content'><p class='js_comment_desc'>"+newcontent+"</p>"+answerimgs+"<div class='hits_zan_box js_hits_zan_box'><div class='left-view'><p class='resource_date'>"+tim+"</p></div><div class='common-iconfont "+isclick+" useful js_hits upv"+dd[l].answerId+"' onclick='addgoodftn(this)'><i class='upthumlogo upthumlogo"+dd[l].answerId+"'></i>赞<span class='js_usefull_num'>"+upnum+"</span></div><div class='useful js_hits commentbtn' data-id='c"+dd[l].answerId+"' onclick='comment(this)'><i></i>回复<span class='js_usefull_num'></span></div></div><div class='common-iconfont zan-person js_zan common"+dd[l].answerId+"' "+commentstyle+"><div class='up-thumb'><i></i><div class='text answer"+dd[l].answerId+"'>"+upers+"</div></div>"+secondword+"</div></div></div>");
                    }
                    else if(page==="allanswer"){
                        $("#allanswer .mainbody").append("<div class='js_tag js_commentP'>"+bestanswer+"<div class='common-head-view'><div class='author-logo'>"+headerimg+"</div><div class='author-info'><div class='author-info1'><div class='author js_author' style='max-width: 330px;'>"+unick+"</div>"+gooverit+"</div><div class='author-info2'>"+secondtitleword+"</div></div></div><div class='comment-main js_content'><p class='js_comment_desc'>"+newcontent+"</p>"+answerimgs+"<div class='hits_zan_box js_hits_zan_box'><div class='left-view'><p class='resource_date'>"+tim+"</p></div><div class='common-iconfont "+isclick+" useful js_hits upv"+dd[l].answerId+"' onclick='addgoodftn(this)'><i class='upthumlogo upthumlogo"+dd[l].answerId+"'></i>赞<span class='js_usefull_num'>"+upnum+"</span></div><div class='useful js_hits commentbtn' onclick='comment(this)' data-eid='"+eid+"' data-id='c"+dd[l].answerId+"' onclick='comment(this)'><i></i>回复<span class='js_usefull_num'></span></div></div><div class='common-iconfont zan-person js_zan common"+dd[l].answerId+"' "+commentstyle+"><div class='up-thumb'><i></i><div class='text answer"+dd[l].answerId+"'>"+upers+"</div></div>"+secondword+"</div></div></div>");
                    }
                }
                htmlword="";
                answerimgs="";
                isclick="";
            }
            else{cangetanswerurl="no";}
            //comment();
            seeuper(dd);
            isover=1;//控制页面滚动
        }
    });
}
//点击查看所有回答所有评论全部回答-----------------------------------------------
$("#addmoreanswerbtn").click(function(){
    if(haveMyid){
        currentIndex=1;
        $("#allanswer .mainbody div").remove();
        getanswer(qid,currentIndex,pageSize,"allanswer");
        $("#allanswer").css("display","block");
        $(window).scrollTop(0);
        $("#page_wrapper").css("display","none");
    }
});
$("#addmoreanswerbtn2").click(function(){
    if(haveMyid){
        currentIndex=1;
        $("#allanswer .mainbody div").remove();
        getanswer(qid,currentIndex,pageSize,"allanswer");
        $("#allanswer").css("display","block");
        $(window).scrollTop(0);
        $("#page_wrapper").css("display","none");
    }
});
$("#allanswerbtn").click(function(){
    if(haveMyid){
        $("#allanswer").css("display","none");
        $("#page_wrapper").css("display","block");
    }
});
$(window).scroll(function(){
    if($("#allanswer").css("display")==="block"){
        var screenH=window.screen.height;//屏幕高度
        var mainheight=$("#allanswer").height();//加载区内主体高度
        var scrollH=$(window).scrollTop();//加载区内滚动隐藏高度
        if((screenH+scrollH+100)>mainheight){
            if(cangetanswerurl==="yes"){
                currentIndex++;
                getanswer(qid,currentIndex,pageSize,"allanswer");
            }
        }
    }
});
//结帖按钮-------------------------------------------------------
var gofinishcurrentIndex=1;
var questionscore=0;
var havemoney=0;//问题又没有钱 0没有 1有
var waheight=window.screen.availHeight;
var canchoiceother=true;
var inputnum=100;
function getallanswer(qid,gofinishcurrentIndex){
    var clicknum=0;//点击次数 选择的人的个数
    $.ajax({
        type:"get",
        datatype:"json",
        url:getanswerurl+(qid)+"&currentIndex="+gofinishcurrentIndex+"&pageSize=15&userId="+id,
        success:function(d){
            console.log(d);
            //如果有分数
            if(questionscore>0){
                havemoney=1;
                var num=0;
                for(var i=0;i< d.Data.proAnswerList.length;i++){
                    var headerimg="<img  src='../img/af8.png'/>";
                    var unick;
                    //if(d.Data.proAnswerList[i].userAva){
                    //    headerimg="<img src='"+imgurl+d.Data.proAnswerList[i].userAva+"'/>";
                    //}
                    //----------------
                    if(d.Data.proAnswerList[i].userAva){
                        if(d.Data.proAnswerList[i].ishideName===1){
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick="匿名";
                        }else{
                            headerimg="<a onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+d.Data.proAnswerList[i].userId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.Data.proAnswerList[i].userAva+"' onload='showloadimg(this)' style='display:none;'></a>";
                            unick=d.Data.proAnswerList[i].userNick;
                        }
                    }else{
                        if(d.Data.proAnswerList[i].ishideName===1){
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick="匿名";
                        }else{
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick=d.Data.proAnswerList[i].userNick;
                        }
                    }
                    //----------------
                    var newcontent=codetoface(d.Data.proAnswerList[i].content);

                    $("#newsplace").append("<div class='ts_cells'> <div class='Cell'> <div class='tc_image'>"+headerimg+"</div> <div class='tc_inner newsplaceright'> <div class='tc_text title'>"+unick+"<span id='span"+d.Data.proAnswerList[i].answerId+"'></span></div><div class='tc_text words'>"+newcontent+"</div> <div class='choiceimg' data-speaker='"+d.Data.proAnswerList[i].userId+"'> <img src='img/hook-no.png' class='imgno' style='display: block;'/> <img src='img/hook01.png' class='imgyes' data-id='"+d.Data.proAnswerList[i].answerId+"' style='display: none'/> </div> </div> </div> </div><div class='inputbox action_menu_container' style='display:none;position:fixed;overflow:hidden;'> <div class='inner'> <div class='action_menu' style='margin-top: 100px;'> <a class='mweb_action_button cancelmoney'>请输入分配比例%</a><a class='mweb_action_button deletekey'><div class='wordinputbox'> <input type='number' maxlength='3' class='inputkey' value='100' min='1' max='100'></div> %</a> <a class='mweb_action_button'><span class='cancel cancelmoney' data-num='"+num+"'>取消</span><span class=' sendword' data-id='"+d.Data.proAnswerList[i].answerId+"'>确定</span></a></div> </div> </div>");
                    num++;
                }
                var clickbtn=document.getElementsByClassName("choiceimg");//选择按钮
                var imgno=document.getElementsByClassName("imgno");//no图标
                var imgyes=document.getElementsByClassName("imgyes");//yes图标
                var inputbox=document.getElementsByClassName("inputbox");//弹出输入框
                var sendword=document.getElementsByClassName("sendword");//弹出输入框确定按钮
                var cancel=document.getElementsByClassName("cancelmoney");//弹出输入框取消按钮
                var inputkey=document.getElementsByClassName("inputkey");//弹出输入框input
                for(var r=0;r<clickbtn.length;r++){
                    clickbtn[r].index=r;
                    clickbtn[r].onclick=function(){
                        if(clickbtn[this.index].dataset.speaker===id){
                            alert("请勿选择自己");
                        }
                        else{
                            if(imgno[this.index].style.display==="block"&&clicknum<3){
                                //没满100 可以选择
                                if(canchoiceother){
                                    clicknum++;
                                    var me=this.index;
                                    imgyes[this.index].style.display="block";
                                    imgno[this.index].style.display="none";
                                    inputbox[this.index].style.display="block";
                                    var last=0;//输入多少钱
                                    sendword[me].onclick=function(e){
                                        if(!inputkey[me].value){inputkey[me].value=1};
                                        //console.log("dianji");
                                        $("#span"+e.target.dataset.id).html("("+inputkey[me].value+"%)");
                                        imgyes[me].setAttribute( 'data-score' ,inputkey[me].value) ;
                                        //allscore[d.Data[me].answer.id]=parseFloat(inputkey[me].value)/100;
                                        inputbox[me].style.display="none";
                                        var choiceimg=document.getElementsByClassName("imgyes");
                                        var tim=0;
                                        for(var r= 0,len=choiceimg.length;r<len;r++){
                                            tim++;
                                            if(choiceimg[r].dataset.score){
                                                last+=parseFloat(choiceimg[r].dataset.score);
                                            };
                                            if(tim==len){
                                                var lastinput=document.getElementsByClassName("inputkey");//弹出输入框input
                                                for(var l= 0,len2=lastinput.length;l<len2;l++){
                                                    console.log("修改value");
                                                    if(last>=100){
                                                        canchoiceother=false;
                                                        lastinput[l].value="";
                                                    }else{
                                                        canchoiceother=true;
                                                        lastinput[l].value=100-last;
                                                        inputnum=100-last;
                                                    }
                                                }
                                            }
                                        }
                                    };
                                }

                            }
                            else if(imgno[this.index].style.display==="none"){
                                if(imgyes[this.index].dataset.id){
                                    $("#span"+imgyes[this.index].dataset.id).html("");
                                }
                                clicknum--;
                                imgyes[this.index].style.display="none";
                                imgyes[this.index].dataset.score="";
                                imgno[this.index].style.display="block";
                                //console.log("clicknum"+clicknum);
                                var last=0;//输入多少钱
                                var choiceimg=document.getElementsByClassName("imgyes");
                                var tim=0;
                                for(var r= 0,len=choiceimg.length;r<len;r++){
                                    tim++;
                                    if(choiceimg[r].dataset.score){
                                        last+=parseFloat(choiceimg[r].dataset.score);
                                    };
                                    if(tim==len){
                                        var lastinput=document.getElementsByClassName("inputkey");//弹出输入框input
                                        for(var l= 0,len2=lastinput.length;l<len2;l++){
                                            console.log("取消操作后value");
                                            if(last>=100){
                                                canchoiceother=false;
                                                lastinput[l].value="";
                                            }else{
                                                canchoiceother=true;
                                                lastinput[l].value=100-last;
                                                inputnum=100-last;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //弹出输入框取消按钮
                for(var r2=0;r2<cancel.length;r2++){
                    cancel[r2].index=r2;
                    cancel[r2].onclick=function(e){
                        clicknum--;
                        var num= e.target.dataset.num;
                        imgyes[num].style.display="none";
                        imgno[num].style.display="block";
                        inputbox[num].style.display="none";
                    };
                }
            }
            else{  /////////////////////////////////////////////////////////////////////没有分数
                for(var i=0;i< d.Data.proAnswerList.length;i++){
                    var headerimg="<img  src='../img/af8.png'/>";
                    var unick;
                    if(d.Data.proAnswerList[i].userAva){
                        if(d.Data.proAnswerList[i].ishideName===1){
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick="匿名";
                        }else{
                            headerimg="<a onclick='usergohref(this)' data-href='otherpeoplepage.html?otherid="+d.Data.proAnswerList[i].userId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.Data.proAnswerList[i].userAva+"' onload='showloadimg(this)' style='display:none;'></a>";
                            unick=d.Data.proAnswerList[i].userNick;
                        }
                    }else{
                        if(d.Data.proAnswerList[i].ishideName===1){
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick="匿名";
                        }else{
                            headerimg="<a><img class='profile_photo_img' src='../img/af8.png'></a>";
                            unick=d.Data.proAnswerList[i].userNick;
                        }
                    }

                    var newcontent=codetoface(d.Data.proAnswerList[i].content);
                    $("#newsplace").append("<div class='ts_cells'> <div class='Cell'> <div class='tc_image'>"+headerimg+"</div> <div class='tc_inner newsplaceright'> <div class='tc_text title'>"+unick+"</div><span id='span"+d.Data.proAnswerList[i].answerId+"'></span><div class='tc_text words'>"+newcontent+"</div> <div class='choiceimg' data-speaker='"+d.Data.proAnswerList[i].userId+"'> <img src='img/hook-no.png' class='imgno' style='display: block;'/> <img src='img/hook01.png' class='imgyes' data-id='"+d.Data.proAnswerList[i].answerId+"' style='display: none'/> </div> </div> </div> </div></div> </div>");
                }
                var clickbtn=document.getElementsByClassName("choiceimg");//选择按钮
                var imgno=document.getElementsByClassName("imgno");//红图标
                var imgyes=document.getElementsByClassName("imgyes");//绿图标
                for(var r=0;r<clickbtn.length;r++){
                    clickbtn[r].index=r;
                    clickbtn[r].onclick=function(){
                        if(clickbtn[this.index].dataset.speaker===id){
                            alert("请勿选择自己");
                        }
                        else{
                            if(imgno[this.index].style.display==="block"&&clicknum<3){
                                clicknum++;
                                var me=this.index;
                                imgyes[this.index].style.display="block";
                                imgno[this.index].style.display="none";
                                //console.log("clicknum"+clicknum);
                            }else if(imgno[this.index].style.display==="none"){
                                if(imgyes[this.index].dataset.id){
                                    $("#span"+imgyes[this.index].dataset.id).html("");
                                }
                                clicknum--;
                                imgyes[this.index].style.display="none";
                                imgno[this.index].style.display="block";
                                //console.log("clicknum"+clicknum);
                            }
                        }
                    }
                }
            }
        }
    });
    //comment();
}
var fromepage="";//最佳答案来源页面
$("#page_wrapper").delegate(".gooveritbtn","click",function(){
    if(haveMyid){
        $("#page_wrapper").css("display","none");
        $("#choicepeople").css("display","block");
        $(window).scrollTop(0);
        $("#newsplace div").remove();
        fromepage="page_wrapper";
        getallanswer(qid,1);
    }
});
$("#allanswer").delegate(".gooveritbtn","click",function(){
    if(haveMyid){
        $("#allanswer").css("display","none");
        $("#choicepeople").css("display","block");
        $(window).scrollTop(0);
        $("#newsplace div").remove();
        fromepage="allanswer";
        getallanswer(qid,1);
    }
});
$("#closethispagebtn").click(function(){
    if(haveMyid){
        if(fromepage==="allanswer"){
            $("#allanswer").css("display","block");
        }else if(fromepage==="page_wrapper"){
            $("#page_wrapper").css("display","block");
        }
        $("#choicepeople").css("display","none");
    }

});
//结帖完成 页面返回
var peoplefinishClick=false;
$("#peoplefinish").click(function(){
    if(haveMyid&&!peoplefinishClick){
        var answerData = [];
        var allmoney=0;
        var imgyes=document.getElementsByClassName("imgyes");//绿图标
        if(imgyes){
            if(havemoney===0){
                for(var i=0;i<imgyes.length;i++){
                    if(imgyes[i].style.display==="block"){
                        var obj = {};
                        obj.answerId =imgyes[i].dataset.id;
                        obj.scorerate =0;
                        answerData.push(obj);
                        allmoney+=parseFloat(imgyes[i].dataset.score);
                    }
                }
                peoplefinishClick=true;
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:overquestionurl,
                    data:{ "answerData": answerData, "questionId": qid },
                    success:function(d){
                        $.cookie("goChangeQue",qid);
                        $.cookie("closeQue",qid);//返回我的问题列表页刷新
                        location.reload();
                    }
                })
            }else if(havemoney===1){
                for(var i=0;i<imgyes.length;i++){
                    if(imgyes[i].style.display==="block"){
                        var obj = {};
                        obj.answerId =imgyes[i].dataset.id;
                        obj.scorerate =parseFloat(imgyes[i].dataset.score)/100;
                        answerData.push(obj);
                        allmoney+=parseFloat(imgyes[i].dataset.score);
                    }
                }
                if(allmoney!=100){
                    //金钱提示
                    $("#moneynews").css("display","block");
                    setTimeout(function(){
                        $("#moneynews").css("display","none");
                    },2000);
                    clearTimeout();
                }else{
                    peoplefinishClick=true;
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:overquestionurl,
                        data:{ "answerData": answerData, "questionId": qid },
                        success:function(d){
                            $.cookie("goChangeQue",qid);
                            $.cookie("closeQue",qid);//返回我的问题列表页刷新
                            location.reload();
                        }
                    })
                }
            }
        }
    }
});
//结帖不能输入0
$("#choicepeople").delegate(".wordinputbox input","input propertychange",function(e) {
    //$('#result').html($(this).val().length + ' characters');
    //console.log(e.target);
    var thisval=e.target.value;
    //console.log(thisval);
    e.target.value=(thisval).match(/[0-9]+/);
    if(/^0+/.test(thisval)){
        e.target.value=(thisval).replace(/^0+/,"");
    };
    if(parseInt(thisval)>parseInt(inputnum)){
        e.target.value=parseInt(inputnum);
    }
});
//点赞操作(回答)
function addgoodftn(e){
    if(haveMyid){

        if(!/isclicked/.test(e.className)){
            var eid=(e.className).match(/[0-9]+/)[0];

            var allnode=document.getElementsByClassName(e.className);
            for(var i= 0,len=allnode.length;i<len;i++){
                allnode[i].className+=" isclicked";
            }

            $.ajax({
                type:"post",
                datatype:"json",
                url:"https://www.pulu.com/webapi/api/PuluAnswerUpdown/AddAnswerUpdown_q",
                data:{"id":"","userId":id,"answerId":eid,"ctime":"","etime":""},
                success:function(data){

                    $(".common"+eid).css("display","block");
                    $(".upv"+eid+" span").html(parseInt($(".upv"+eid+" span").html())+1);
                    $(".answer"+ eid).append("<span class='heartspan' data-uid='"+ $.cookie("MYID")+"'>"+ $.cookie("MYNICK")+"</span>");
                }
            })
        }
    }
}
//点赞问题
$("#upquebtn").click(function(){
    if($.cookie("MYID")){
        $.ajax({
            type:"post",
            url:upQueUrl,
            data:{"contentid":qid,"userid":id,"isup":1},
            success:function(d){
                console.log(d);
                if(d.Message=="该用户已经存在点赞"){
                    $("#collectword a").html("您已经点过赞");
                }
                else{
                    $("#collectword a").html("点赞成功");

                    $("#goodbtn").css("backgroundImage","url(../img/redheart.png)");

                    $("#goodbtn .word").attr("class","word clicked");
                    if($.cookie("MYNICK")){
                        upnick.push($.cookie("MYNICK"));
                        upuserid.push($.cookie("MYID"));
                        showuper(upnick,upuserid);
                    }
                }
                if(modalbg.style.display=="block"&&modal.style.display=="block"){
                    modalbg.className+=' animate_out';
                    modal.className+=' animate_out';
                }
                timer=setTimeout(changeclass,100);
                $("#collectword").css("display","block");
                setTimeout(function(){
                    $("#collectword").css("display","none");
                },1000);
                clearTimeout();
            }
        })
    }
    else{
        //alert("没有用户ID");
    }
});
//查看所有点赞者
$(".allupers").click(function(){
    if($.cookie("MYID")){
        location.href="showallpay.html?eid="+qid+"#queAllUp";
    }
});
function addgood(){
    if(haveMyid){
        var goodbtn=document.querySelectorAll(".Upvote.Button");
        var gooodcount=document.getElementsByClassName("count");
        for(var g=0;g<goodbtn.length;g++){
            goodbtn[g].index=g;
            goodbtn[g].onclick=function(){
                if(goodbtn[this.index].className==="Upvote Button"){
                    goodbtn[this.index].className="Upvote Button isclicked";
                    console.log(this.index);
                    gooodcount[this.index].innerHTML=parseFloat(gooodcount[this.index].innerHTML)+1;
                    $.ajax({
                        type:"post",
                        datatype:"json",
                        url:"https://www.pulu.com/webapi/api/PuluAnswerUpdown/AddAnswerUpdown",
                        data:{"id":"","userId":id,"answerId":goodbtn[this.index].id,"ctime":"","etime":""},
                        success:function(data){
                            console.log(data);
                        }
                    })
                }
            }
        }
    }

}
//查看所有评论页面
function comment(e){
    if(haveMyid){
        if(e.dataset.uid&&e.dataset.uid!=id){
            var sendeid="";
            var replyname="";
            if(e.dataset.reply){
                sendeid="&reply="+e.dataset.reply;
                replyname="&replyname="+e.dataset.replyname;
            };
            location.href="comment.html?aid="+e.dataset.id+sendeid+replyname;
        }else if(!e.dataset.uid){
            var sendeid="";
            var replyname="";
            if(e.dataset.reply){
                sendeid="&reply="+e.dataset.reply;
            };
            location.href="comment.html?aid="+e.dataset.id+sendeid+replyname;
        }
        //var e=arguments.callee.caller.arguments[0]||event;
        //if (e && e.stopPropagation) {
        //    e.stopPropagation();
        //} else if (window.event) {
        //    window.event.cancelBubble = true;
        //}
        //var commentbtn=document.querySelectorAll(".commentbtn");
        //for(var g=0;g<commentbtn.length;g++){
        //    commentbtn[g].index=g;
        //    commentbtn[g].onclick=function(e){
        //        console.log("点击了");
        //        if(e.target.nodeName==="IMG"){
        //            if(e.target.parentNode.dataset.reply){
        //                location.href="comment.html?aid="+commentbtn[this.index].id+"&reply="+e.target.parentNode.dataset.reply+"&replyname="+e.target.parentNode.dataset.replyname;
        //            }else{
        //                location.href="comment.html?aid="+commentbtn[this.index].id;
        //            }
        //        }else{
        //            if(e.target.dataset.reply){
        //                location.href="comment.html?aid="+commentbtn[this.index].id+"&reply="+e.target.dataset.reply+"&replyname="+e.target.dataset.replyname;
        //            }else{
        //                location.href="comment.html?aid="+commentbtn[this.index].id;
        //            }
        //        }
        //    }
        //}
    }

}
//查看所有点赞者
//页面切换
document.getElementById("upvotersbtn").onclick=function(){
    if(haveMyid){
        $("#upvoters .ts_cells li.Cell").remove();
        document.getElementById("upvoters").style.display="none";
        document.getElementById("page_wrapper").style.display="block";
    }
};
function seeuper(dd){
    if(haveMyid){
        var saub=document.getElementsByClassName("seeallupvoters");
        var saubid=[];
        for(var i=0;i<saub.length;i++){
            saub[i].index=i;
            saub[i].onclick=function(){
                if(dd[this.index].userids.length>0){
                    saubid=dd[this.index].userids;
                    document.getElementById("upvoters").style.display="block";
                    document.getElementById("page_wrapper").style.display="none";
                    $.ajax({
                        type:"post",
                        dataType: "json",
                        url:seealluperurl,
                        data:{"persons":dd[this.index].userids},
                        success:function(data){
                            //console.log(data);
                            if(data.Data&&data.Data.length>0){
                                for(var r=0;r<data.Data.length;r++){
                                    var job="";
                                    var edu="";
                                    var cit="";
                                    var thisid="";
                                    if(data.Data[r].jobs&&data.Data[r].jobs.length>0){
                                        job=" · "+data.Data[r].jobs[0].typename;
                                    }
                                    if(data.Data[r].education){
                                        edu=" · "+data.Data[r].education;
                                    }
                                    if(data.Data[r].city){
                                        cit=" · "+data.Data[r].city;
                                    }
                                    if(id===data.Data[r].userId){
                                        thisid="";
                                    }else if(id!==data.Data[r].userId){
                                        thisid=" href='otherpeoplepage.html?otherid="+data.Data[r].userId+"'";
                                    }
                                    var headerimg="<img class='profile_photo_img' src='../img/af8.png'/>";
                                    if(data.Data[r].userAva){
                                        headerimg="<img class='profile_photo_img' src='http://42.62.66.198:8003/"+data.Data[r].userAva+"'/>";
                                    }
                                    $("#upvoters .Section .ts_cells").append("<li class='Cell has_image'><div class='tc_image'>"+headerimg+"</div><a class='tc_inner sticky_highlight'"+thisid+" href='otherpeoplepage.html?otherid="+data.Data[r].userId+"'><span class='tc_text'><span class='user'>"+data.Data[r].nick+"</span></span><div class='AnswerActorCredibilityInfo'><span>"+cit+"</span><span>"+job+"</span><span>"+edu+"</span></div></a><div class='tc_discl'></div><div class='tc_stroke'></div></li>")
                                }
                            }
                        }
                    });
                }
            }
        }
    }

}
//编辑问题
$("#changeexp").click(function(){
    if($.cookie("MYID")){
        if(canEdit){
            //$.cookie("changeQue","que")//区分当前是否为问题
            //if(is_weixn()){
                $.cookie("changeQue","que");
                location.href="changeexp.html?eid="+qid;
            //}else{
            //    location.href="http://www.pulu.com/changeexp.html?id="+id+"&eid="+qid+"&changeQue=que";
            //}
        }
        else{
            if(modalbg.style.display=="block"&&modal.style.display=="block"){
                modalbg.className+=' animate_out';
                modal.className+=' animate_out';
            }
            timer=setTimeout(changeclass,100);
            alert("悬赏已在审核中，请耐心等候");
        }
    }
});
//加载好友列表 用于页面内部评论召唤好友---------------------------------------------------
//if(haveMyid){
//    $.ajax({
//        datatype:"json",
//        type:"get",
//        url:friendlisturl+id,
//        success:function(d){
//            if(d.Data.length>0){
//                //排序
//                friendarr= d.Data;
//                function compare(property){
//                    return function(a,b){
//                        var value1 = pinyin.getCamelChars(a[property]);
//                        var value2 = pinyin.getCamelChars(b[property]);
//                        return value1.localeCompare(value2);
//                    }
//                }
//                friendarr.sort(compare("friendnick"));
//                hasharr={};//判断字母是否存在
//                for(var i=0;i<friendarr.length;i++){
//                    friendarr[this.index]=i;
//                    //如果昵称开头为汉字或英文字母
//                    var key=pinyin.getCamelChars(friendarr[i].friendnick[0]);
//                    if(key.match(/[a-z|A-Z]/)){
//                        if(!hasharr[pinyin.getCamelChars(friendarr[i].friendnick[0])]){
//                            hasharr[pinyin.getCamelChars(friendarr[i].friendnick[0])]=i;
//                        }
//                        $("#a").append("<div class='section_header section_header_gray "+key+"' data-num='"+i+"' style='display:none'> <span class='"+key+"'>"+key+"</span> </div><div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox'  class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
//                    }else{
//                        $("#jinghao").css("display","block");
//                        $("#jinghao").append("<div class='friends' id='"+friendarr[i].friendId+"'> <input type='checkbox'  class='addchatpeoplebtn' data-fid='"+friendarr[i].friendId+"'><div class='imageplace'><a href='otherpeoplepage.html?otherid="+friendarr[i].friendId+"'><img src='http://42.62.66.198:8003/"+friendarr[i].headimg+"' class='topic_photo_img'/> </a> </div> <div class='innerplace tc_text'>"+friendarr[i].friendnick+"</div> </div>");
//                    };
//                }
//                for(var key in hasharr){
//                    $("#choicefriend .section_header.section_header_gray."+key).eq(0).css("display","block");
//                };
//            }
//        }
//    });
//}
//点击判断
if(!$.cookie("MYID")){
    haveMyid=false;
    var id;
    if($.cookie("fromuser")){
        id=$.cookie("fromuser");
    }
    document.onclick=function(){
        var newid=(location.href).match(/fromuser=[0-9a-z]+/)[0].split("=")[1];
        location.href="https://www.pulu.com/weixin/index.html?qid="+qid+"#fromuser="+newid;
    }
}
//二维码关注骚扰弹框
// else{
//     if(is_weixn()){
//         $.ajax({
//             type:"get",
//             url:harassurl+$.cookie("MYID"),
//             success:function(d){
//                 //console.log(d);
//                 //没有关注
//                 if(!d.Data){
//                     $("#harass").css("display","block");
//                 }
//             }
//         });
//     }
// }
$("#closeharass").click(function(){
    $("#harass").css("display","none");
});
function closeqr(){
    if($.cookie("MYID")){
        $.ajax({
            type:"post",
            url:changeqrurl,
            data:{"userId":$.cookie("MYID")},
            success:function(d){
                $("#harass").css("display","none");
            }
        })
    }
    else{
        $("#harass").css("display","none");
    }
}
$("#closeharass1 #closealltime").click(function(){
    closeqr();
});
$("#closeharass1 label").click(function(){
    closeqr();
});
//好友列表页 展开隐藏--------------------------------------------
$("#friendhelp").click(function(){
    $("#shareword").css("display","none");
    $("#page_wrapper").css("display","none");
    $("#choicefriend").css("display","block");
});
$("#firendgobackbtn").click(function(){
    $("#page_wrapper").css("display","block");
    $("#shareword").css("display","block");
    $("#choicefriend").css("display","none");
});
$(window).scroll(function(){
    var mainheight=$(".home_feed").height();
    //console.log("加载区域高度："+mainheight);
    var windowheight=$(window).height();
    //console.log("窗口高度："+windowheight);
    var what=$(".home_feed").offset().top;
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    if(chajuli<cz&&isover===1){
        isover=0;
        if(document.getElementById("choicepeople").style.display==="block"){
            gofinishcurrentIndex++;
            getallanswer(qid,gofinishcurrentIndex);
            console.log("页面滚动了")
        }
    }
});
//键盘事件 搜索--------------------------------------------------
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        var word=document.getElementById("searchinput").value;
        if(word){
            if(word.match(/^\s+$/g)){
                console.log("没有填信息")
            }else{
                location.href="searchdetail.html?searchKey="+word;
            }
        }
    }
};